import {hrAjax as proFetch} from 'src/hrpub/common/utils/utils';
import setButtonStatus from "../../../container/functions/setButtonStatus";
import handleAllpks from "../../../container/functions/handleAllpks";
import updateCardButtonStatus from "../../../container/functions/updateCardButtonStatus";
import {toast} from 'nc-lightapp-front';

export default function saveBlacklistInfo() {
    const {orgVal, includeCheckedPsn, form, updateState, cardPagination} = this.props;

    const flag = form.isCheckNow('blackcard');
    if (!flag) return;

    let postData = {
        model: form.getAllFormValue('blackcard'),
        pk_org: orgVal && orgVal.refpk,
        includeCheckedPsn
    };

    return proFetch({
        url: '/nccloud/hrhi/blacklist/BlackListSaveAction.do',
        body: postData,
    })
        .then((res) => {
            if (res.success) {
                const pk_psndoc_bad = res.data.form.blackcard.rows[0].values.pk_psndoc_bad.value;
                const pk_psndoc = res.data.form.blackcard.rows[0].values.pk_psndoc.value;
                updateState({
                    page: 'card',
                    pk_psndoc_bad,
                    pk_psndoc
                }, () => {
                    setButtonStatus.call(this, 'card');
                    updateCardButtonStatus.call(this, 'card', orgVal, res.data.form.blackcard.rows[0].values);
                    toast({
                        color: 'success',
                        content: this.props.json['hi6007-000000']/* 国际化处理： 保存成功*/
                    });
                });
                form.setFormStatus('blackcard', 'browse');
                form.setFormItemsVisible('blackcard', res.data.visiableItem);
                form.setAllFormValue({'blackcard': res.data.form.blackcard});
                if (res.data.form.blackcard.rows[0].values.cause.value == null) {
                    form.setFormItemsValue('blackcard', {'cause': {value: '', display: ''}});
                }
                handleAllpks.add(pk_psndoc_bad);
                cardPagination.setCardPaginationId({
                    id: pk_psndoc_bad,
                    status: 1
                });
            }
        });
}
